package com.huabo.contract.mysql.mapper;

import com.hbfk.util.PageInfo;
import com.huabo.contract.mysql.entity.TblAttachmentMySql;
import com.huabo.contract.mysql.entity.TblDispuinfoMySql;
import com.huabo.contract.mysql.entity.TblLegalDisputregistrationMySql;
import com.baomidou.mybatisplus.core.mapper.BaseMapper;
import org.apache.ibatis.annotations.*;

import java.math.BigDecimal;
import java.util.List;

/**
 * <p>
 *  Mapper 接口
 * </p>
 *
 * @author huabo
 * @since 2022-03-16
 */
public interface TblLegalDisputregistrationMySqlMapper extends BaseMapper<TblLegalDisputregistrationMySql> {

    @Select("SELECT * FROM TBL_LEGAL_DISPUTREGISTRATION tld\n" +
            "LEFT JOIN TBL_CYHW_UNIT tcu on tld.CONTRACTINFO = tcu.CONTRACTID\n" +
            "WHERE tld.DISPUTEID = #{disputeid}")
    TblLegalDisputregistrationMySql selectDisputeId(Integer disputeid);

    @SelectProvider(type=TblLegalDisputregistrationMySqlMapperSqlConfig.class,method="findListByPageInfo")
    List<TblLegalDisputregistrationMySql> findListByPageInfo(PageInfo<TblLegalDisputregistrationMySql> pageInfo, TblLegalDisputregistrationMySql dispute, BigDecimal pid);

    @Select("SELECT * FROM TBL_LEGAL_DISPUTREGISTRATION WHERE DISPUTEID = #{pid}")
    String findDisputeIdsForDisputeClose(BigDecimal pid);

    @SelectProvider(type=TblLegalDisputregistrationMySqlMapperSqlConfig.class,method="findListByPageInfoCount")
    Integer findListByPageInfoCount(TblLegalDisputregistrationMySql dispute, BigDecimal pid);

    @InsertProvider(type=TblLegalDisputregistrationMySqlMapperSqlConfig.class,method="saveDiputregistration")
    @Options(useGeneratedKeys=true, keyProperty="disputeid", keyColumn="DISPUTEID")
    void saveDiputregistration(TblLegalDisputregistrationMySql dispute);

    @InsertProvider(type=TblLegalDisputregistrationMySqlMapperSqlConfig.class,method="saveAttacheMent")
    void saveAttacheMent(Integer type, Integer bid, BigDecimal aid);

    @Delete("DELETE FROM TBL_LEGAL_DISPUTREGISTRATION WHERE DISPUTEID = #{attid}")
    void deleteRelation(String attid);

    @Delete("DELETE FROM TBL_LEGAL_DISPUTREGISTRATION WHERE DISPUTEID = #{disputeId}")
    void removecaseInformation(Integer disputeId);


    @Select("SELECT * FROM TBL_LEGAL_DISPUTREGISTRATION WHERE DISPUTEID = #{disputeId}")
    TblLegalDisputregistrationMySql findByDisputeId(Integer disputeId);

    @SelectProvider(type=TblLegalDisputregistrationMySqlMapperSqlConfig.class,method="findListByPageInfoDispute")
    List<TblLegalDisputregistrationMySql> findListByPageInfoDispute(PageInfo<TblLegalDisputregistrationMySql> pageInfo, TblLegalDisputregistrationMySql dispute, BigDecimal pid,String disputeIds);

    @SelectProvider(type=TblLegalDisputregistrationMySqlMapperSqlConfig.class,method="findListByPageInfoDisputeCount")
    Integer findListByPageInfoDisputeCount(TblLegalDisputregistrationMySql dispute, BigDecimal pid,String disputeIds);

    @SelectProvider(type = TblLegalDisputregistrationMySqlMapperSqlConfig.class,method = "findListByDispute")
    List<TblLegalDisputregistrationMySql> findListByDispute(PageInfo<TblLegalDisputregistrationMySql> pageInfo, TblLegalDisputregistrationMySql dispute);

    @SelectProvider(type = TblLegalDisputregistrationMySqlMapperSqlConfig.class,method = "findListByDisputeCount")
    Integer findListByDisputeCount(TblLegalDisputregistrationMySql dispute);

    @Select("SELECT * FROM TBL_LEGAL_DISPUTREGISTRATION tld\n" +
            "LEFT JOIN TBL_CYHW_UNIT tcu on tld.CONTRACTINFO = tcu.CONTRACTID WHERE tld.DISPUTEID = #{disputeId}")
    @Options(useGeneratedKeys=true, keyProperty="disputeId", keyColumn="DISPUTEID")
    TblLegalDisputregistrationMySql findDisputeId(Integer disputeId);

    @UpdateProvider(type=TblLegalDisputregistrationMySqlMapperSqlConfig.class,method="updateDiputregistration")
    void updateDiputregistration(TblLegalDisputregistrationMySql stration);

    @Select("SELECT tst.REALNAME AS zxstaffname,tld.*, ts.REALNAME AS realname,tcu.*,org.* " +
            "FROM TBL_LEGAL_DISPUTREGISTRATION tld " +
            "LEFT JOIN TBL_STAFF tst on tld.DISPUTEUNDERTAKER = tst.STAFFID " +
            "LEFT JOIN TBL_CYHW_UNIT tcu ON tld.CONTRACTINFO = tcu.CONTRACTID " +
            "LEFT JOIN TBL_STAFF ts ON tld.CREATESTAFF = ts.STAFFID " +
            "INNER JOIN TBL_ORGANIZATION org ON ts.ORGID = org.ORGID " +
            " WHERE tld.DISPUTEID =  #{disputeId}")
    TblLegalDisputregistrationMySql findBydisputeId(Integer disputeId);

    @Select("SELECT * FROM TBL_LEGAL_DISPUTREGISTRATION tld\n" +
            "LEFT JOIN TBL_CYHW_UNIT tcu on tld.CONTRACTINFO = tcu.CONTRACTID\n" +
            "WHERE tld.DISPUTEID = #{disputeId} AND tld.LINKORG = #{orgid}")
    TblLegalDisputregistrationMySql findByOrgid(Integer disputeId, BigDecimal orgid);

    @SelectProvider(type=TblLegalDisputregistrationMySqlMapperSqlConfig.class,method="findAttacheMentByBid")
    List<TblAttachmentMySql> findAttacheMentByBid(Integer type, Integer bid);

    @DeleteProvider(type=TblLegalDisputregistrationMySqlMapperSqlConfig.class,method="deleteAttacheMentByBid")
    void deleteAttacheMentByBid(Integer type, Integer aid);

    @DeleteProvider(type=TblLegalDisputregistrationMySqlMapperSqlConfig.class,method="deleteAttacheMents")
    void deleteAttacheMents(Integer type, BigDecimal bid);

    @SelectProvider(type=TblLegalDisputregistrationMySqlMapperSqlConfig.class,method="findDisputeIdsForDispute")
    List<TblDispuinfoMySql> findDisputeIdsForDispute(String colName, String tableName, String orgColName, String whSql, BigDecimal oid);


//    @Select("SELECT * FROM TBL_LEGAL_CLOSEINFORMATION tlc \n" +
//            "LEFT JOIN TBL_STAFF ts on tlc.CREATESTAFF = ts.STAFFID\n" +
//            "LEFT JOIN TBL_LEGAL_DISPUTREGISTRATION tld on tlc.DISPUTINFO = tld.DISPUTEID WHERE tlc.CLOSEID = #{closeId}")
//    TblLegalCloseinformation selectCloseid(Integer closeid);
}
